package com.jin.webvideo.externalInterfaces.video;

import com.jin.webvideo.exception.UnavailableServiceException;
import com.jin.webvideo.externalInterfaces.PlatformSupport;
import com.jin.webvideo.externalInterfaces.entity.Filmography;
import com.jin.webvideo.externalInterfaces.entity.FilmographyInfo;
import com.jin.webvideo.externalInterfaces.youku.YouKuBaseInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class YoukuApi extends AbstractVideoAPI {

    @Autowired
    private YouKuBaseInfo baseInfoHandle;

    @Override
    public Filmography baseInfo(String docid, String tvid) throws UnavailableServiceException {
        return baseInfoHandle.baseInfo(docid, tvid);
    }

    @Override
    public List<FilmographyInfo> videoInfoList(String docid, String tvid, Integer pageNo, Integer pageSize) throws UnavailableServiceException {
        int start = (pageNo - 1)*pageSize;
        int end = pageNo*pageSize;
        try {
            return baseInfoHandle.videoInfos(String.valueOf(start), String.valueOf(end), tvid);
        } catch (Exception e) {
            e.printStackTrace();
            throw new UnavailableServiceException();
        }
    }

    @Override
    String platformName() {
        return PlatformSupport.PLATFORM_YOUKU;
    }
}
